#include "DetailDocument.h"
#include "..\Renderer.h"

DetailDocument::DetailDocument()
{
	_model = new data::DetailDef(
		"", "",
		data::Texture("", Transform::ZERO, 0.0f, 0.0f),
		0.0f, 0.0f, 0.0f, 0.0f);
}


DetailDocument::DetailDocument(const wxString& filePath)
{
	_model = data::LoadDetailDef( filePath.ToStdString() );
}

DetailDocument::~DetailDocument()
{
	delete _model;
	_model = 0;
}

void DetailDocument::Save(const wxString& filePath) const {
	data::SaveDetailDef( _model, filePath.ToStdString() );
}

void DetailDocument::Draw(Renderer& renderer, wxPaintDC& dc) const {
	const IIterable<Circle>* circles = _model->GetVertices();
	Vector<Vec2>* vertices = new Vector<Vec2>();

	for( IteratorPtr<Circle> circlesIter( circles->GetIterator() ); !circlesIter->IsEnd(); circlesIter->Next() )
	{
		Circle circle = circlesIter->Current();
		renderer.DrawCircle(dc, circle.Center, circle.Radius, wxColor(255, 100, 100));

		vertices->Add(circlesIter->Current().Center);
	}
	renderer.DrawPolygon(dc, vertices, wxColor(255, 100, 100));
}
